<template>
  <AMISRenderer :schema="schema" />
</template>

<script setup>
import AMISRenderer from '@/components/AMISRenderer.vue'
import detail from "./detail"

function createTable(checkStatus){
  return {
    type: 'crud',
    name: 'entpWaitCheckTable',
    syncLocation: false,
    api: '/upms/mgr/org/entp/apply/list',
    defaultParams:{
      checkStatus: checkStatus
    },
    autoFillHeight: true,
    columnsTogglable: false,
    footerToolbar: [
      'statistics',
      'switch-per-page',
      'pagination'
    ],
    autoGenerateFilter: {
      showBtnToolbar: false,
      columnsNum: 4
    },
    columns:[
      {
        label: '企业名称',
        name: 'orgName',
        searchable: {
            type: 'input-text',
            name: 'orgName',
            label: '企业名称',
            clearable: true
        }
      },
      {
        label: '统一社会信用代码',
        name: 'registerCode',
        searchable: {
            type: 'input-text',
            name: 'registerCode',
            label: '统一社会信用代码',
            clearable: true,
            labelWidth: 130,
        }
      },
      {
        label: '企业类型',
        name: 'entpTypeStr',
        searchable: {
            type: 'select',
            name: 'entpType',
            label: '企业类型',
            source: '/base/dict/options/entp-type',
            clearable: true,
            labelWidth: 130,
        }
      },
      {
        label: '被授权人',
        name: 'authName'
      },
      {
        label: '被授权人手机号',
        name: 'authPhone'
      },
      {
        name: 'provinceName',
        label: '省',
        hiddenOn: '1',
        searchable: {
          type: 'select',
          name: 'provinceCode',
          label: '省',
          source: '${provinceList}',
          valueField: 'regionCode',
          labelField: 'regionName',
          clearable: true,
        }
      },
      {
        name: 'cityName',
        label: '市',
        hiddenOn: '1',
        searchable: {
          type: 'select',
          name: 'cityCode',
          label: '市',
          source: {
            url: '/upms/user/region/children?parentId=${provinceCode}',
            sendOn: '${provinceCode}',
          },
          valueField: 'regionCode',
          labelField: 'regionName',
          clearable: true,
        }
      },
      {
        name: 'areaName',
        label: '县',
        hiddenOn: '1',
        searchable: {
          type: 'select',
          name: 'areaCode',
          label: '县',
          source: {
            url: '/upms/user/region/children?parentId=${cityCode}',
            sendOn: '${cityCode}',
          },
          valueField: 'regionCode',
          labelField: 'regionName',
          clearable: true,
        }
      },
      {
        label: '申请时间',
        name: 'gmtCreated'
      },
      {
        name: 'changeFlag',
        label: '申请类型',
        type: 'mapping',
        map: {
          "0": "<span class='label label-success'>注册</span>",
          "1": "<span class='label label-warning'>变更</span>",
        }
      },
      {
        type: 'operation',
        label: '操作',
        buttons: [
          {
            label: '查看',
            type: 'button',
            actionType: 'dialog',
            visibleOn: '${checkStatus != 1}',
            dialog:{
              title: '企业信息',
              closeOnEsc: true,
              showErrorMsg: false,
              body: detail,
              size: 'full',
              actions:[
                {
                  type: 'button',
                  label: '返回',
                  level: 'primary',
                  actionType: 'close'
                }
              ]
            },
          },
          {
            label: '审核',
            type: 'button',
            actionType: 'dialog',
            visibleOn: '${checkStatus == 1}',
            dialog:{
              title: '审核',
              closeOnEsc: true,
              showErrorMsg: false,
              body: detail,
              size: 'full'
            }
          }
        ]
      }
    ]
  }
}

const schema = {
  type: 'page',
  name: 'orgEntpApplyPage',
  initApi: '/upms/user/region/province',
  body:[
    {
      type: 'tabs',
      tabsMode: 'line',
      tabs:[
        {
          title: '待审核',
          body:[
            createTable(1)
          ]
        },
        {
          title: '审核通过',
          body:[
            createTable(2)
          ]
        },
        {
          title: '审核不通过',
          body:[
            createTable(3)
          ]
        }
      ]
    }
  ]
}

</script>
